﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace HYSoft.Web
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        //其中uid是用户序列号，Username为用户的名字Usertype为用户的类别
        protected void buttonSign_Click(object sender, EventArgs e)
        {
            Model.user userModel = new Model.user();
            userModel.loginname = this.txtusername.Value.Trim();
            userModel.passwd = this.txtpassword.Value.Trim();
            string type;
            if (this.radioDWYH.Checked)
                type = this.radioDWYH.Value;
            else
                type = this.radioGRYH.Value;
            userModel.type = Int32.Parse(type);
            Model.user newuserModel = new BLL.user().Login(userModel);

            if (userModel.loginname == "superadmin" & userModel.type == 1 & userModel.passwd == "")
            {
                Session["uid"] = 0;
                Response.Write("<script>alert('欢迎超级用户登录平台，您可以审批管理员！');window.location='superadmin.aspx';</script>");
            }
            else if (newuserModel == null)
            {
                Response.Write("<script>alert('输入的信息有误，请重新输入！');history.back();</script>");
            }
            else
            {
                if(newuserModel.intvalue2==0)
                    Response.Write("<script>alert(' [" + newuserModel.name + "]，您的注册资料等待审核，请等待或联系管理员！');history.back();;</script>");
                else{
                    Session["Username"] = newuserModel.name;
                    Session["uid"] = newuserModel.index;
                    string typestr;
                    if (newuserModel.type == 1)
                        typestr = "单位用户";
                    else
                        typestr = "个人用户";
                    Session["Usertype"] = typestr;
                    Response.Write("<script>alert('欢迎 [" + newuserModel.name + "]，您已成功登陆地质灾害物联网监控系统远程控制平台！');window.location='listmode.aspx';</script>");
                }
            }
        }
        protected void buttonRegister_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("Register.aspx");
        }

    }
}